﻿using System;
#if DEBUG
using System.Diagnostics;
#endif // #if DEBUG
using System.Net;
using System.Xml;
using System.Collections.Generic;

using FRL.DebtChased.Extensions;

#if WORKFLOWEDITOR
using FRL.DebtChased.WorkflowEditor;
#endif // 

#if REPOSITORY
using FRL.DebtChased.Repository;
#endif // #if REPOSITORY

namespace FRL.DebtChased.WorkflowObjects
{

	/// <summary>
	/// Declaration of WorkflowAction_NotifyManager class
	/// Workflow action for notifying manager of workflow
	/// </summary>
	public class WorkflowAction_NotifyManager : WorkflowAction_Base
	{

		/////////////////////////////////////////////////////////////
		// Enumerations

		/////////////////////////////////////////////////////////////
		// Constants

		public const string XmlElementName = "WorkflowAction_NotifyManager";
		public const string BoingLabel = "Notify Mng";

		/////////////////////////////////////////////////////////////
		// Attributes

		private string m_strMessage;
		public string Message
		{
			get { return m_strMessage; }
			set { m_strMessage = value; }
		}

		/////////////////////////////////////////////////////////////
		// Implementation

		protected override string _getElementName()
		{
			return XmlElementName;
		}

#if WORKFLOWEDITOR
		public override string GetBoingLabel()
		{
			return BoingLabel;
		}
#endif // #if WORKFLOWEDITOR

#if WORKFLOWEDITOR
		public override string[] GetBoingSubStrings()
		{

			// Declare return variable
			string[] Ftmp = new string[2];

			// Put message in top row
			if (string.IsNullOrEmpty(m_strMessage))
				Ftmp[0] = "[no message for manager]";
			else
				Ftmp[0] = m_strMessage;

			// Return variable
			return Ftmp;

		}
#endif // #if WORKFLOWEDITOR

		protected override void _writeParameters(XmlWriter w)
		{

			// Write members as parameters
			w.WriteAttributeString("message", m_strMessage);

		}

		protected override void _readParameters(XmlReader r)
		{

			// Read parameters
			m_strMessage = r.GetAttribute("message");

		}

		public override string GetSummary(Workflow.eSummaryFormat SummaryFormat)
		{

			// Declare return variable
			string strFtmp = null;

			// Compare formats
			if (SummaryFormat == Workflow.eSummaryFormat.Audit)
			{
				strFtmp = "Notify Manager";
			}
			else if (SummaryFormat == Workflow.eSummaryFormat.Clockwork)
			{
				strFtmp = "Notify Manager";
			}
#if DEBUG
			else
				Debug.Assert(false);
#endif // #if DEBUG

			// Return variable
			return strFtmp;

		}

#if REPOSITORY
		public override List<AccountNote> Process(DebtChasedEntities ent, Account acc, AccountInvoice inv)
		{

			// Declare return variable
			List<AccountNote> Ftmp = new List<AccountNote>();

			// Add an alert for this account-invoice
			Ftmp.Add( AccountNote.Append(
				ent, 
				acc, 
				inv, 
				m_strMessage, 
				null, 
				AccountNote.eFlags.ClockworkService | AccountNote.eFlags.WaitingForHuman
			));

			// Return variable
			return Ftmp;

		}
#endif // #if REPOSITORY

	}

}
